home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / basic / num2word.bas (.txt) < prev    next >
Encoding:
GW-BASIC  |  1984-03-05  |  3.1 KB  |  47 lines

  1. 1  REM IBM PC ------- NUM-WORD ---------
  2. 2  REM VERSION$= "V1.2"    '8/14/82
  3. 3  REM Author: Herb Shear, 1590 Vineyard Dr. Los Altos, CA 94022
  4. 4  REM Adapted from NUMWORD [Creative Computing, 6/82 p176] by Michael Sorens
  5. 5  '
  6. 6  'Author commentary: Returning P$ rather than printing while crunching allows
  7. 7  'the calling program to vary print fonts, add "protection" and otherwise
  8. 8  'play games with the literal and the available print space.
  9. 9  'The limit for SNG precision is about $130,000.00.  Stating the purchase
  10. 10  'price on a deposit receipt for a simple home sale requires larger values.
  11. 11  'Handling the error condition, [P$=""] is up to the calling program.
  12. 12  'Other enhancements are the "-" where required by english syntax, leading
  13. 13  'zero/NO/100, only and setting it up about as close to a callable procedure
  14. 14  'as one can achieve in BASIC. All of which is just polish on Sorens's gem.
  15. 15  ' The literal syntax has been approved by an experienced bank officer.
  16. 16  ' NONE and EXACTLY are not proper syntax.
  17. 100  CLS
  18. 110  INPUT "ENTER AMOUNT"; SUM#
  19. 120  GOSUB 5000 NUM-LITERAL
  20. 130  IF LEN(P$) THEN PRINT P$: PRINT ELSE PRINT "Exceeds accuracy limits, use a smaller number!"
  21. 140  GOTO 110
  22. 150  '-------all the above is just for demo ---ps: list w/ LISTER for readabilityedit 80
  23. 160  '
  24. 5000  'Procedure NUM-LITERAL(SUM#,P$); value SUM#; ------------
  25. 5010  '         returns literal expression of SUM# in P$
  26. 5020  ' LSUM#, TEMP1#, TEMP2#, TEMP3#, TEMP4# TEMP5#, CENTS%, I%, NUMWORD$
  27. 5030  P$ = "": IF SUM# > 1.98E+14 THEN RETURN ELSE LSUM#=SUM#
  28. 5040  IF LEN(NUMWORD$(2)) THEN ELSE GOSUB 5200
  29. 5050  CENTS%=INT((LSUM#-INT(LSUM#))*100+0.5)  :LSUM#=INT(LSUM#)
  30. 5060  IF LSUM# THEN GOSUB 5100: P$ = P$ + "AND " ELSE P$ = "ONLY "
  31. 5070  IF CENTS% THEN P$ = P$ +RIGHT$("0"+MID$(STR$(CENTS%),2,2),2) ELSE P$=P$+"NO"
  32. 5080  P$ = P$ + "/100 DOLLARS"
  33. 5090  RETURN
  34. 5100  '-------- recursive subroutine to express numbers as words-----
  35. 5110  IF LSUM# > 1E+12 THEN TEMP5# = LSUM#-INT(LSUM#/1E+12)*1E+12: LSUM# = INT(LSUM#/1E+12): GOSUB 5100: P$ =P$ + "TRILLION ": LSUM# = TEMP5#
  36. 5120  IF LSUM# > 1E+09 THEN TEMP4# = LSUM#-INT(LSUM#/1E+09)*1E+09: LSUM# = INT(LSUM#/1E+09)  :GOSUB 5100: P$ = P$ + "BILLION ": LSUM# = TEMP4#
  37. 5130  IF LSUM# > 999999 THEN TEMP3# = LSUM#-INT(LSUM#/1E+06)*1E+06: LSUM# = INT(LSUM#/1E+06): GOSUB 5100: P$ = P$ + "MILLION ": LSUM# = TEMP3#
  38. 5140  IF LSUM# > 999 THEN TEMP2# = LSUM#-INT(LSUM#/1000)*1000: LSUM# = INT(LSUM#/1000): GOSUB 5100: P$ = P$ + "THOUSAND ": LSUM# = TEMP2#
  39. 5150  IF LSUM# > 99 THEN TEMP1# = LSUM#: LSUM# = INT(LSUM#/100) :GOSUB 5100: P$ = P$ + "HUNDRED ": LSUM# = TEMP1#-LSUM#*100
  40. 5160  IF LSUM# > 19 THEN P$ = P$ + NUMWORD$(INT(LSUM#/10)): LSUM# = LSUM#-10*INT(LSUM#/10): IF LSUM# THEN P$ =P$ + "-": ELSE  P$=P$ +" "
  41. 5170  IF LSUM# THEN P$ = P$ + NUMWORD$(LSUM#+9)+" "
  42. 5180  RETURN
  43. 5190  '--------- initilization --------------------------------------------
  44. 5200  ERASE NUMWORD$:DIM NUMWORD$(28): RESTORE 5210: FOR I%=2 TO 28: READ NUMWORD$(I%): NEXT: RETURN
  45. 5210  DATA TWENTY,THIRTY,FORTY,FIFTY,SIXTY,SEVENTY,EIGHTY,NINETY
  46. 5220  DATA ONE,TWO,THREE,FOUR,FIVE,SIX,SEVEN,EIGHT,NINE,TEN,ELEVEN,TWELVE,            THIRTEEN,FOURTEEN,FIFTEEN,SIXTEEN,SEVENTEEN,EIGHTEEN,NINETEEN
  47.